/**
 * 
 */
package com.wsj.web.action.homeSiteNews;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.wsj.service.IBmClassTypeServ;
import com.wsj.service.IHomeSiteAdBannerDescriptServ;
import com.wsj.service.IHomeSiteAdBannerServ;
import com.wsj.service.IHomeSiteNewsClassServ;
import com.wsj.service.IHomeSiteNewsServ;
import com.wsj.service.IHomeSiteResearchReportFileUploadServ;
import com.wsj.service.IUserManagerServ;
import com.wsj.util.exception.BusinessException;
import com.wsj.util.tool.HtmlCreateObj;
import com.wsj.util.tool.RequestUtils;
import com.wsj.web.action.BaseAction;
import com.wsj.web.constant.homeSiteNews.HomeSiteNewsConstant;
import com.wsj.web.constant.homeSiteNews.IndexPageContent;
import com.wsj.web.subclass.displayBean.HomeSiteNews.HomeSiteIndexPageColumnBean;
import com.wsj.web.vo.homeSite.AutoPlay;
import com.wsj.web.vo.homeSite.HomeSiteNews;
import com.wsj.web.vo.homeSite.HomeSiteNewsClass;
import com.wsj.web.vo.homeSite.HomeSiteUploadFile;

/**
 * @author fengbin  createTime:2009-7-18
 *  新闻站首页
 */
public class HomeSiteNewsIndexAction extends BaseAction{
	
	
//	生成html页面对象
	private HtmlCreateObj htmlCreateObj;

	/** 资讯分类接口 */
	private IHomeSiteNewsClassServ homeSiteNewsClassServ;
	
	/** 资讯接口 */
	private IHomeSiteNewsServ homeSiteNewsServImpl;
	
	/** 广告接口 */
	private IHomeSiteAdBannerServ homeSiteAdBannerServ;
	
	/** 广告描述接口 */
	private IHomeSiteAdBannerDescriptServ homeSiteAdBannerDescriptServ;
	
	/******
	 * 用户接口
	 */
	private IUserManagerServ userManagerServ;
	
	private IBmClassTypeServ bmClassTypeServImpl;
	
	/*********
	 * 研究报告上传服务层
	 */
	 private IHomeSiteResearchReportFileUploadServ homeSiteResearchReportFileUploadServ;
	
	

	/******
	 * 默认情况下执行这个方法
	 * 
	 *  获取首页所有的信息,如果带有自动创建静态页的情况下,那么自动创建静态页
	 */
	public ActionForward indexHtmlPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		//跳转首页静态页
		return mapping.findForward("indexHtml");
		
		
	}
	
	
	/******
	 * 默认情况下执行这个方法
	 * 
	 *  获取首页所有的信息,如果带有自动创建静态页的情况下,那么自动创建静态页
	 */
	public ActionForward indexPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		 //获取整个页面的新闻内容
		 this.getAllPageNewsTitleList(request);
		
		return mapping.findForward("indexPage");
		
		
	}
	
	/********
	 * 创建首页的静态页面
	 */
	public ActionForward createIndexPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		 //获取整个页面的新闻内容
		 //生成静态页面
		String filePath="index.html";
		htmlCreateObj.setCreateFileParament(RequestUtils.getRequestHost(request)+HomeSiteNewsConstant.homeSiteIndexPath, "html/index/", filePath);
//		 生成静态页面
		htmlCreateObj.createHtmlFile(request, response);
		
		//跳转
		return mapping.findForward("indexHtml");
		
	}
	
		
	
    
	private void getAllPageNewsTitleList(HttpServletRequest request) {
		
		 //获取滚动新闻
		 this.getAutoPlayNewsList(request);
		
		 //获取第一大横栏新闻内容  滚动图片推荐新闻  ,推荐头条 ,今天推荐 ,今日要闻
		 this.getFirstBarNewsTitleList(request);
		 
		 //获取第二横栏新闻内容 上: 本站观点,行业报告,研究报告  下: 个人理财,股市新手,时政要闻
		 this.getSecondBarNewsTitleList(request);
		 
		
		 
		 //获取第三栏左边新闻内容 编辑推荐 ,国外经济,期货市场,基金数据分析,理财故事
		 this.getThirdLeftBarNewsTitleList(request);
		 
		 //获取第三栏右边新闻内容 热门板块,一周推荐 , 供应信息 ,求购信息,代理信息,合作信息
		 this.getThirdRightBarNewsTitleList(request);
		 
	}


	/**********
	 * 获取前3个滚动新闻
	 * @param request
	 */
	private void getAutoPlayNewsList(HttpServletRequest request) {
		
		try {
			//获取前3个 滚动新闻
			List<AutoPlay> autoPlayList = this.getHomeSiteNewsServImpl().getAutoPlayNewsList(3);
			request.setAttribute("autoPlayList", autoPlayList);
		} catch (Exception e) {
			this.getLogger().error("getAutoPlayNewsList error",e);
		}
		
	}


	/**********
	 * 获取最近的10个研究报告文件
	 * @param request
	 */
    private void getTheLastTenResearchReport(HttpServletRequest request) {
		
    	try {
			List<HomeSiteUploadFile>  homeSiteUploadFileTopList =this.getHomeSiteResearchReportFileUploadServ().getResearchReportTop(12);
			request.setAttribute("homeSiteUploadFileTopList", homeSiteUploadFileTopList);
		} catch (BusinessException e) {
			this.getLogger().error("获取最近的10个研究报告文件 出错",e);
		}
	}



	/***
     * 获取第一大横栏新闻内容  滚动图片推荐新闻  ,推荐头条 ,今天头条 ,冯涛论市
     * @param request
     */
	
	private void getFirstBarNewsTitleList(HttpServletRequest request) {
		
		//滚动图片推荐新闻  6条文本新闻 0条图片新闻 0条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_GDTPTJXW = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_GDTPTJXW_NAME,6,0,IndexPageContent.GUIDE_NEWS_DISPLAY_NO);
		
		request.setAttribute("COLUMN_GDTPTJXW", COLUMN_GDTPTJXW);
		
		//获取推荐头条 ,今日头条
		this.getTodayTopTitle(request);
		
		//冯涛论市  10条文本新闻 0条图片新闻 0条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_JRYW = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_JRYW_NAME,10,0,IndexPageContent.GUIDE_NEWS_DISPLAY_NO);
		
		request.setAttribute("COLUMN_JRYW", COLUMN_JRYW);
		
	}
	
	
	/*******
	 * 获取今日头条,推荐头条  获取15条
	 * @param request
	 */
	private void getTodayTopTitle(HttpServletRequest request) {
		
		try {
			
			List<HomeSiteNews> homeSiteNewsList = this.getHomeSiteNewsServImpl().getTodayTopTitle(15);
			
			List<HomeSiteNews> homeSiteNewsListTop = null;
			List<HomeSiteNews> homeSiteNewsListDetail = null;
			
			if(homeSiteNewsList!=null  && !homeSiteNewsList.isEmpty()){
				
				 homeSiteNewsListTop = new  ArrayList<HomeSiteNews>();
				 homeSiteNewsListDetail =new  ArrayList<HomeSiteNews>();
				
				 for(int j=0;j<homeSiteNewsList.size();j++){
					 HomeSiteNews homeSiteNews =(HomeSiteNews)homeSiteNewsList.get(j);
					 if(j<3){
						 homeSiteNewsListTop.add(homeSiteNews);
					 }else{
						 homeSiteNewsListDetail.add(homeSiteNews);
					 }
				 }
			}
			
			request.setAttribute("homeSiteNewsListTop", homeSiteNewsListTop);
			request.setAttribute("homeSiteNewsListDetail", homeSiteNewsListDetail);
			
		} catch (BusinessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}



	


	/*******
	 * 获取第二横栏新闻内容 本站观点,行业报告,研究报告  个人理财,股市新手,时政要闻
	 * @param request
	 */
	private void getSecondBarNewsTitleList(HttpServletRequest request) {
		
		
		//本站观点  12条文本新闻 0条图片新闻 0条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_BZGD = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_BZGD_NAME,12,0,IndexPageContent.GUIDE_NEWS_DISPLAY_NO);
		request.setAttribute("COLUMN_BZGD", COLUMN_BZGD);
		
		//行业报告  12条文本新闻 0条图片新闻 0条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_HYBG = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_HYBG_NAME,12,0,IndexPageContent.GUIDE_NEWS_DISPLAY_NO);
		request.setAttribute("COLUMN_HYBG", COLUMN_HYBG);
		
		 //研究报告  12条最新研究报告
		 //获取第二栏最近12个研究报告
		 this.getTheLastTenResearchReport(request);
		
		
		
		//个人理财  12条文本新闻 0条图片新闻 0条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_GRLC = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_GRLC_NAME,12,0,IndexPageContent.GUIDE_NEWS_DISPLAY_NO);
		request.setAttribute("COLUMN_GRLC", COLUMN_GRLC);
		
//		股市新手  12条文本新闻 0条图片新闻 0条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_GSXS = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_GSXS_NAME,12,0,IndexPageContent.GUIDE_NEWS_DISPLAY_NO);
		request.setAttribute("COLUMN_GSXS", COLUMN_GSXS);
		
		//时政要闻  12条文本新闻 0条图片新闻 0条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_SZYW = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_SZYW_NAME,12,0,IndexPageContent.GUIDE_NEWS_DISPLAY_NO);
		request.setAttribute("COLUMN_SZYW", COLUMN_SZYW);
		
		
		
	}
	
	
	/*******
	 * 获取研究报告
	 * @param i
	 * @return
	 */
	private List<HomeSiteUploadFile> getResearchReport(int top) {
		try {
			return this.getHomeSiteResearchReportFileUploadServ().getResearchReportTop(12);
		} catch (BusinessException e) {
			this.getLogger().error("获取研究报告出错",e);
		}
		return new ArrayList<HomeSiteUploadFile>();
	}


	/*********
	 * 获取第三栏左边新闻内容 编辑推荐 ,国外经济 ,期货市场 ,基金数据分析, 理财故事
	 * @param request
	 */
	private void getThirdLeftBarNewsTitleList(HttpServletRequest request) {
		
		//编辑推荐  0条文本新闻 3条图片新闻 0条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_BJTJ = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_BJTJ_NAME,0,3,IndexPageContent.GUIDE_NEWS_DISPLAY_NO);
		request.setAttribute("COLUMN_BJTJ", COLUMN_BJTJ);
		
		//国外经济 5条文本新闻 0条图片新闻 1条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_GWJJ = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_GWJJ_NAME,5,0,IndexPageContent.GUIDE_NEWS_DISPLAY_YES);
		request.setAttribute("COLUMN_GWJJ", COLUMN_GWJJ);
		
		//期货市场 5条文本新闻 0条图片新闻 1条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_QHSC = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_QHSC_NAME,5,0,IndexPageContent.GUIDE_NEWS_DISPLAY_YES);
		request.setAttribute("COLUMN_QHSC", COLUMN_QHSC);
		
		//基金数据分析 5条文本新闻 0条图片新闻 1条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_JJSJFX = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_JJSJFX_NAME,5,0,IndexPageContent.GUIDE_NEWS_DISPLAY_YES);
		request.setAttribute("COLUMN_JJSJFX", COLUMN_JJSJFX);
		
		//理财故事 5条文本新闻 0条图片新闻 1条引导阅读新闻
		HomeSiteIndexPageColumnBean COLUMN_LCGS = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_LCGS_NAME,5,0,IndexPageContent.GUIDE_NEWS_DISPLAY_YES);
		request.setAttribute("COLUMN_LCGS", COLUMN_LCGS);
		
		
	}
	
	
	/***********
	 * 
	 * 获取第三栏右边新闻内容 热门板块,一周推荐 , 供应信息 ,求购信息,代理信息,合作信息
	 * 
	 * @param request
	 */
	private void getThirdRightBarNewsTitleList(HttpServletRequest request) {
		
		try {
			//热门板块 4条文本新闻 0条图片新闻 1条引导阅读新闻
			HomeSiteIndexPageColumnBean COLUMN_RMBK = this.getHomeSiteNewsServImpl().getColumnNews(IndexPageContent.INDEX_RMBK_NAME,4,0,IndexPageContent.GUIDE_NEWS_DISPLAY_YES);
			request.setAttribute("COLUMN_RMBK", COLUMN_RMBK);
			
			/******
			 * 一周推荐栏目
			 */
			HomeSiteNewsClass oneWeekCommentNewsClass = this.homeSiteNewsClassServ.loadNewsClassByNames("一周推荐");
			
			/******
			 * 一月推荐栏目
			 */
			HomeSiteNewsClass oneMouthCommentNewsClass = this.homeSiteNewsClassServ.loadNewsClassByNames("一月推荐");
			
			if(oneWeekCommentNewsClass!=null){
				//一周推荐
				List<HomeSiteNews>  oneWeekCommentList = this.getHomeSiteNewsServImpl().getCommentNewsCollectList(oneWeekCommentNewsClass.getId(),10);
				HomeSiteIndexPageColumnBean COLUMN_ONEWEEK_COMMENT=new HomeSiteIndexPageColumnBean();
				COLUMN_ONEWEEK_COMMENT.setNewsCount(10);
				COLUMN_ONEWEEK_COMMENT.setHomeSiteNewsList(oneWeekCommentList);
				request.setAttribute("COLUMN_ONEWEEK_COMMENT", COLUMN_ONEWEEK_COMMENT);
			}
			
			
			if(oneMouthCommentNewsClass!=null){
				//一月推荐
				List<HomeSiteNews>  oneMouthCommentList = this.getHomeSiteNewsServImpl().getCommentNewsCollectList(oneMouthCommentNewsClass.getId(),10);
				HomeSiteIndexPageColumnBean COLUMN_ONEMOUTH_COMMENT=new HomeSiteIndexPageColumnBean();
				COLUMN_ONEMOUTH_COMMENT.setNewsCount(10);
				COLUMN_ONEMOUTH_COMMENT.setHomeSiteNewsList(oneMouthCommentList);
				request.setAttribute("COLUMN_ONEMOUTH_COMMENT", COLUMN_ONEMOUTH_COMMENT);
			}
			
			
			
		} catch (BusinessException e) {
			
			 this.getLogger().error("getThirdRightBarNewsTitleList error",e);
		}
		
		
		
		
	}



	



	



	



	public IHomeSiteAdBannerDescriptServ getHomeSiteAdBannerDescriptServ() {
		return homeSiteAdBannerDescriptServ;
	}

	public void setHomeSiteAdBannerDescriptServ(
			IHomeSiteAdBannerDescriptServ homeSiteAdBannerDescriptServ) {
		this.homeSiteAdBannerDescriptServ = homeSiteAdBannerDescriptServ;
	}

	public IHomeSiteAdBannerServ getHomeSiteAdBannerServ() {
		return homeSiteAdBannerServ;
	}

	public void setHomeSiteAdBannerServ(IHomeSiteAdBannerServ homeSiteAdBannerServ) {
		this.homeSiteAdBannerServ = homeSiteAdBannerServ;
	}

	public IHomeSiteNewsClassServ getHomeSiteNewsClassServ() {
		return homeSiteNewsClassServ;
	}

	public void setHomeSiteNewsClassServ(
			IHomeSiteNewsClassServ homeSiteNewsClassServ) {
		this.homeSiteNewsClassServ = homeSiteNewsClassServ;
	}

	public IHomeSiteNewsServ getHomeSiteNewsServImpl() {
		return homeSiteNewsServImpl;
	}

	public void setHomeSiteNewsServImpl(IHomeSiteNewsServ homeSiteNewsServImpl) {
		this.homeSiteNewsServImpl = homeSiteNewsServImpl;
	}

	public HtmlCreateObj getHtmlCreateObj() {
		return htmlCreateObj;
	}

	public void setHtmlCreateObj(HtmlCreateObj htmlCreateObj) {
		this.htmlCreateObj = htmlCreateObj;
	}

	public IUserManagerServ getUserManagerServ() {
		return userManagerServ;
	}

	public void setUserManagerServ(IUserManagerServ userManagerServ) {
		this.userManagerServ = userManagerServ;
	}
	

	
	public IBmClassTypeServ getBmClassTypeServImpl() {
		return bmClassTypeServImpl;
	}



	public void setBmClassTypeServImpl(IBmClassTypeServ bmClassTypeServImpl) {
		this.bmClassTypeServImpl = bmClassTypeServImpl;
	}



	public IHomeSiteResearchReportFileUploadServ getHomeSiteResearchReportFileUploadServ() {
		return homeSiteResearchReportFileUploadServ;
	}



	public void setHomeSiteResearchReportFileUploadServ(
			IHomeSiteResearchReportFileUploadServ homeSiteResearchReportFileUploadServ) {
		this.homeSiteResearchReportFileUploadServ = homeSiteResearchReportFileUploadServ;
	}



}
